package com.lry.basic.excel.fill;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.alibaba.excel.write.metadata.WriteSheet;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

public class TestFill {

    String templateFileName = "d:\\simpleFill.xlsx";

    // 方案1 根据对象填充
    String fileName = "d:\\simple.xlsx";

    ExcelWriter  excelWriter;
    WriteSheet writeSheet;
    {

        excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();
        writeSheet = EasyExcel.writerSheet(0,"user").build();
    }

    int i=0;

    @Test
    public void simpleFill() {
        if(i>=5){
            // 千万别忘记关闭流
            excelWriter.finish();
            return;
        }
        i++;

        excelWriter.fill(data(), writeSheet);

        simpleFill();

    }
    private List<FillData> data(){
        List<FillData> data = new ArrayList<>();
        for(int i=0;i<10;i++){
            FillData fillData = new FillData();
            fillData.setName("张三sdfasd"+i);
            fillData.setNumber(5.2);
            data.add(fillData);
        }
       return data;
    }


}
